package nl.han.ica.ap.searchengine.client.searching;

import java.util.ArrayList;
import java.util.List;

import nl.han.ica.ap.searchengine.client.ResultPage;
import nl.han.ica.ap.searchengine.client.SearchQuery;
import nl.han.ica.ap.searchengine.client.SearchResults;

public class WordMatcher implements SearchStrategy{
	
	public static void main(String[] args) {
		WordMatcher wm = new WordMatcher();
		wm.test();
		
	}
	
	public WordMatcher() {
		
	}
	
	public void test () {
		List<String> list = new ArrayList<String>();
		list.add("test");
		list.add("doei");
		SearchQuery q = new SearchQuery(list);
		process(q);
	}

	public SearchResults process(SearchQuery query) {
		List<String> database = new ArrayList<String>();
		database.add("testtestaefldoeikajl;atestdoeiajef;aktest");
		database.add("test alkefj;test test");
		database.add("doei doei doei doei");
		SearchResults result = new SearchResults();
		for (String db : database) {
			int count =0;
			for (String s : query.getKeywords()) {
				int lastIndex = 0;
				while(lastIndex != -1){
					lastIndex = db.indexOf(s,lastIndex);
					if(lastIndex != -1){
			             count ++;
			             lastIndex+=s.length();
					}
				}
			}
			result.addPage(ResultPage.createSimplePage("Url", count));
		}
		return result;
	}
}